package com.ch3cooh.servercachetest.dao;

import com.ch3cooh.servercachetest.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;

@Mapper
@CacheConfig(cacheNames = "users")
public interface UserMapper {

    @Select("SELECT * FROM t_user")
    @Cacheable(value = "all_users",keyGenerator="wiselyKeyGenerator")
    List<User> selectAll();

    @Select("SELECT * FROM t_user WHERE user_id= #{id}")
    @Cacheable(value="select_user",key="'user[id='+#p0+']'")
    User selectById(@Param("id") Integer id);

}
